from selenium.webdriver.support.ui import WebDriverWait







class Base():
    def __init__(self, driver):
        self.driver=driver
    def open_url(self, url):
        self.driver.get(url)
    def find_element(self, loc):
        WebDriverWait(self.driver,20,0.5).until(lambda driver:self.driver.find_element(*loc).is_displayed())
        return self.driver.find_element(*loc)
    def click(self, loc):
        self.find_element(loc).click()
    def send_leys(self, loc, text):
        self.find_element(loc).send_keys(text)
    def get_text(self, loc):
        return self.find_element(loc).text
    # 切换窗口
    def new_window(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])

    # 页面滑动
    def window_scroll(self,num):
        self.driver.execute_script(f'window.scrollTo(0,{num})')
    # 关闭弹窗的方法
    def alert_(self):
        alert = self.driver.switch_to.alert
        alert.dismiss()
    # 切换iframe框架
    def frame(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))


